home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3475 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: news.iadfw.net!usenet
  2. From: Mark Nelson <markn@airmail.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Vector of abstract classes using STL
  5. Date: Mon, 22 Jan 1996 16:57:15 -0600
  6. Organization: customer of Internet America
  7. Message-ID: <3104164B.68A0@airmail.net>
  8. References: <3103699A.79F8@ce.kth.se>
  9. NNTP-Posting-Host: dal06-21.ppp.iadfw.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b3 (Win95; I)
  14.  
  15. Anders Olsson wrote:
  16. > I have an abstract class Shape, that has pure virtual functions.
  17. > From this class I derive rectangle and circle classes.
  18. > I want to use a vector for storing the shapes.
  19. > I've tried using a vector<Shape>, but I get compiler errors because
  20. > the Shape class cannot be instantiated. This must be the wrong way of
  21. > doing it I understand.
  22. > I think I have to use a vector<Shape*> but does the vector delete
  23. > the shape elements when the program finishes?
  24.  
  25. No, it doesn't.  The vector destructor will call the explicity 
  26. destructor for Shape *, which will probably do nothing at all.  So to 
  27. get good cleanup, you might want to create a wrapper class that performs 
  28. an auto_ptr type function.
  29.  
  30. Mark Nelson
  31. http://web2.airmail.net/markn
  32.